package com.example.springboot26.controller;

import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * 项目名称：springboot26
 * 类 名 称：LoginController
 * 类 描 述：TODO
 * 创建时间：2020/2/4 11:35 上午
 */
@Controller
public class LoginController {
    @PostMapping(value = "/user/login")
    public String login(@RequestParam("username") String username,
                        @RequestParam("password") String password,
                        Map<String, Object> map, HttpSession httpSession) {
        if (!StringUtils.isEmpty(username) && "123".equals(password)) {
            // 登陆成功后防止表单重复提交
            httpSession.setAttribute("loginUser", username);
            return "redirect:/main.html";
        } else {
            map.put("msg", "用户名或者密码错误");
            return "login";
        }
    }
}
